package acm.广东工业大学新生赛;

import java.util.Scanner;

public class D {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count = sc.nextInt();
        while (count-- > 0) {
            int x=sc.nextInt();
            int target=sc.nextInt();
            if (target%5!=0&&target!=x&&x<target&&(x%6!=0||target%6!=0)){
                System.out.println(-1);
                continue;
            }
        }
    }
}
